package com.yxym.homework;

public class homework04 {
    public static void main(String[] args) {
        Cellphone cellphone  = new Cellphone();
//        cellphone.testWork(new ICalculate() {
//            @Override
//            public double work(double n1, double n2) {
//                return n1 + n2;
//            }
//        });//匿名内部类
        /*
        new ICalculate() {
            @Override
            public double work(double n1, double n2) {
                return n1 + n2;
            }
        }运行结构是匿名内部类

         */
        cellphone.testWork(new ICalculate() {
            @Override
            public double work(double n1, double n2) {
                return n1 + n2;
            }

            @Override
            public void say() {
                System.out.println("奥利给...");
            }
        });
    }
}
interface ICalculate{
    //work()方法
    double work(double n1,double n2);
    void say();

    //该方法交由匿名内部类
}
class Cellphone{
    //调用testWork方法时，传入了实现接口的匿名内部类
    public void testWork(ICalculate iCalculate ){
        double result = iCalculate.work(100.0,200.0);
        System.out.println("计算后的结果是：" + result);
    }
}
